//
//  LXMyCommissionHeaderView.m
//  LvXi_newVersion
//
//  Created by 诸葛孔明 on 16/9/6.
//  Copyright © 2016年 SJT. All rights reserved.
//............................................................................................//
//......................................我的佣金头部视图......................................//
//............................................................................................//

#import "LXMyCommissionHeaderView.h"
#import "LXWithdrawController.h"//提现控制器

@interface LXMyCommissionHeaderView()
/**整体背景图片*/
@property (nonatomic,weak) UIImageView *backgroundImageView;
/**返回按钮*/
@property (nonatomic,weak) UIButton *backButton;
/**提现按钮*/
@property (nonatomic,weak) UIButton *getMoneyButton;
/**佣金标题*/
@property (nonatomic,weak) UILabel *titleLabel;
/**佣金文字*/
@property (nonatomic,weak) UILabel *commissionLabel;
/**分佣规则*/
@property (nonatomic,weak) UIButton *ruleButton;

//...................................分割线......................................//

//*******************************底部可用佣金整体********************************//
/**底部整体容器*/
@property (nonatomic,weak) UIView *bottomView;
/**可用佣金*/
@property (nonatomic,weak) UILabel *canUseCommissionLabel;
/**等待发放佣金*/
@property (nonatomic,weak) UILabel *prepareCommissionLabel;
/**分割线*/
@property (nonatomic,weak) UIView *cutLineView;

@end

@implementation LXMyCommissionHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        UIImageView *backgroundImageView = [[UIImageView alloc] init];
        backgroundImageView.image = [UIImage imageNamed:@"Commission-background"];
        [self addSubview:backgroundImageView];
        self.backgroundImageView = backgroundImageView;
        
        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [backButton setBackgroundImage:[UIImage imageNamed:@"mine_back"] forState:UIControlStateNormal];
        backButton.imageView.contentMode = UIViewContentModeScaleToFill;
        [self addSubview:backButton];
        self.backButton = backButton;
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.text = @"佣金";
        titleLabel.font = [UIFont systemFontOfSize:17];
        [self addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        UIButton *getMoneyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [getMoneyButton addTarget:self action:@selector(getMoneyBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [getMoneyButton setTitle:@"提现" forState:UIControlStateNormal];
        getMoneyButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [getMoneyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self addSubview:getMoneyButton];
        self.getMoneyButton = getMoneyButton;
        
        UILabel *commissionLabel = [[UILabel alloc] init];
        commissionLabel.text = @"佣金";
        commissionLabel.textColor = [UIColor whiteColor];
        commissionLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:commissionLabel];
        self.commissionLabel = commissionLabel;
        
        UIButton *ruleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [ruleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [ruleButton setTitle:@"分佣规则" forState:UIControlStateNormal];
        ruleButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [ruleButton addTarget:self action:@selector(ruleBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:ruleButton];
        self.ruleButton = ruleButton;
        
        UILabel *moneyLabel = [[UILabel alloc] init];
        moneyLabel.font = [UIFont systemFontOfSize:30];
        moneyLabel.textColor = [UIColor whiteColor];
        moneyLabel.text = [NSString stringWithFormat:@"%zd元",5000];
        [self addSubview:moneyLabel];
        self.moneyLabel = moneyLabel;
        
        
//.....................................我是分割线................................//
        //底部容器
        UIView *bottomView = [[UIView alloc] init];
        bottomView.backgroundColor = HexColor(@"#359A2F");
        [self addSubview:bottomView];
        self.bottomView = bottomView;
        
        UIView *cutLineView = [[UIView alloc] init];
        cutLineView.backgroundColor = [UIColor whiteColor];
        [self.bottomView addSubview:cutLineView];
        self.cutLineView = cutLineView;
        
        UILabel *canUseCommissionLabel = [[UILabel alloc] init];
        canUseCommissionLabel.font = [UIFont systemFontOfSize:12];
        canUseCommissionLabel.textColor = [UIColor whiteColor];
        canUseCommissionLabel.text = @"可用佣金";
        [self.bottomView addSubview:canUseCommissionLabel];
        self.canUseCommissionLabel = canUseCommissionLabel;
        
        UILabel *canUseMoneyLabel = [[UILabel alloc] init];
        canUseMoneyLabel.font = [UIFont systemFontOfSize:16];
        canUseMoneyLabel.textColor = [UIColor whiteColor];
        canUseMoneyLabel.text = [NSString stringWithFormat:@"%zd元",4999];
        [self.bottomView addSubview:canUseMoneyLabel];
        self.canUseMoneyLabel = canUseMoneyLabel;
        
        UILabel *prepareCommissionLabel = [[UILabel alloc] init];
        prepareCommissionLabel.font = [UIFont systemFontOfSize:12];
        prepareCommissionLabel.textColor = [UIColor whiteColor];
        prepareCommissionLabel.text = @"待发放佣金";
        [self.bottomView addSubview:prepareCommissionLabel];
        self.prepareCommissionLabel = prepareCommissionLabel;
        
        UILabel *prepareMoneyLabel = [[UILabel alloc] init];
        prepareMoneyLabel.font = [UIFont systemFontOfSize:16];
        prepareMoneyLabel.textColor = [UIColor whiteColor];
        prepareMoneyLabel.text = [NSString stringWithFormat:@"%zd元",1];
        [self.bottomView addSubview:prepareMoneyLabel];
        self.prepareMoneyLabel = prepareMoneyLabel;
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //背景图片
    self.backgroundImageView.x = 0;
    self.backgroundImageView.y = 0;
    self.backgroundImageView.width = ScreenWidth;
    self.backgroundImageView.height = self.height;
    
    //返回按钮
    self.backButton.x = MineRatio(15);
    self.backButton.y = MineRatio(30);
    self.backButton.width = MineRatio(9);
    self.backButton.height = MineRatio(15);
    
    //佣金标题
    self.titleLabel.width = [self.titleLabel.text sizeInAre:MaxSize font:self.titleLabel.font].width;
    self.titleLabel.height = [self.titleLabel.text sizeInAre:MaxSize font:self.titleLabel.font].height;
    self.titleLabel.centerX = self.centerX;
    self.titleLabel.y = self.backButton.y;
    
    //提现按钮
    self.getMoneyButton.width = 30;
    self.getMoneyButton.height = 15;
    self.getMoneyButton.x = self.width - self.getMoneyButton.width - self.backButton.x;
    self.getMoneyButton.y = self.backButton.y;
    
    //佣金文字
    self.commissionLabel.width = [self.commissionLabel.text sizeInAre:MaxSize font:self.commissionLabel.font].width;
    self.commissionLabel.height = [self.commissionLabel.text sizeInAre:MaxSize font:self.commissionLabel.font].height;
    self.commissionLabel.x = MineRatio(20);
    self.commissionLabel.y = self.backButton.botton + MineRatio(30);
    
    //分佣规则
    self.ruleButton.width = MineRatio(50);
    self.ruleButton.height = MineRatio(15);
    self.ruleButton.x = self.width - self.ruleButton.width - self.backButton.x;
    self.ruleButton.y = self.commissionLabel.y;
    
//.....................................我是分割线................................//
    
    //底部整体容器
    self.bottomView.width = ScreenWidth;
    self.bottomView.height = MineRatio(45);
    self.bottomView.x = 0;
    self.bottomView.y = self.height - self.bottomView.height;
    
    //底部分割线
    self.cutLineView.centerX = self.bottomView.centerX;
    self.cutLineView.y = MineRatio(9);
    self.cutLineView.width = 1;
    self.cutLineView.height = self.bottomView.height - self.cutLineView.y * 2;
    
    //可用佣金
    self.canUseCommissionLabel.width = [self.canUseCommissionLabel.text sizeInAre:MaxSize font:self.canUseCommissionLabel.font].width;
    self.canUseCommissionLabel.height = [self.canUseCommissionLabel.text sizeInAre:MaxSize font:self.canUseCommissionLabel.font].height;
    self.canUseCommissionLabel.x = MineRatio(20);
    self.canUseCommissionLabel.y = (self.bottomView.height - self.canUseCommissionLabel.height) * 0.5;
    
    //可用佣金金额
    self.canUseMoneyLabel.width = [self.canUseMoneyLabel.text sizeInAre:MaxSize font:self.canUseMoneyLabel.font].width;
    self.canUseMoneyLabel.height = [self.canUseMoneyLabel.text sizeInAre:MaxSize font:self.canUseMoneyLabel.font].height;
    self.canUseMoneyLabel.x = self.canUseCommissionLabel.right + MineRatio(27);
    self.canUseMoneyLabel.centerY = self.canUseCommissionLabel.centerY;
    
    //待发放佣金
    self.prepareCommissionLabel.width = [self.prepareCommissionLabel.text sizeInAre:MaxSize font:self.prepareCommissionLabel.font].width;
    self.prepareCommissionLabel.height = [self.prepareCommissionLabel.text sizeInAre:MaxSize font:self.prepareCommissionLabel.font].height;
    self.prepareCommissionLabel.x = self.cutLineView.right + MineRatio(27);
    self.prepareCommissionLabel.centerY = self.canUseCommissionLabel.centerY;
    
    //待发放佣金金额
    self.prepareMoneyLabel.width = [self.prepareMoneyLabel.text sizeInAre:MaxSize font:self.prepareMoneyLabel.font].width;
    self.prepareMoneyLabel.height = [self.prepareMoneyLabel.text sizeInAre:MaxSize font:self.prepareMoneyLabel.font].height;
    self.prepareMoneyLabel.x = self.prepareCommissionLabel.right + MineRatio(27);
    self.prepareMoneyLabel.centerY = self.canUseCommissionLabel.centerY;
    
    //佣金总金额
    self.moneyLabel.width = [self.moneyLabel.text sizeInAre:MaxSize font:self.moneyLabel.font].width;
    self.moneyLabel.height = [self.moneyLabel.text sizeInAre:MaxSize font:self.moneyLabel.font].height;
    self.moneyLabel.x = (self.width - self.moneyLabel.width) * 0.5;
    self.moneyLabel.y = self.bottomView.top - self.moneyLabel.height - MineRatio(40);
    
}

#pragma mark - 事件处理
//返回按钮点击
- (void)backButtonClick
{
    [[self getCurrentVC].navigationController popViewControllerAnimated:YES];
}

//提现按钮点击
- (void)getMoneyBtnClick
{
    LXWithdrawController *drawVc = [[LXWithdrawController alloc] init];
    [[self getCurrentVC].navigationController pushViewController:drawVc animated:YES];

}

//分佣规则按钮点击
- (void)ruleBtnClick
{
    NSLog(@"%s",__func__);
}

@end
